<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
$this->model('model')->checkuser();
$return=array();
if($_RQ['op']=='get'){
	$return['item']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
	if($return['item']['groupid']){
		$return['item']['group']=pdo_getcolumn('core_member_groups',array('id'=>$return['item']['groupid'],'uniacid'=>$_SESSION['uniacid']),'title');
	}else{
		$return['item']['group']='普通会员';
	}
	$return['params']['status']=0;
	$setting=uni_setting('member_setting');
	$return['registerset']=uni_setting('register');
	$return['item']['barcode']='0-';
	$return['item']['barcode'].=$_SESSION['uid']+10000000000000000;
	$return['item']['sign']=$setting['sign']['open'];
	$return['item']['tixians']=$setting['member']['tixians'];
	$return['item']['cardbg']=$setting['cardbg'];
	$member['ideal_money']=pdo_getcolumn('core_ideal_money',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'money');
	$return['item']['ideal_money']=$member['ideal_money']?$member['ideal_money']:'0.00';
	$return['item']['mycoupon']=pdo_count('jy_weishop_coupon_getlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'isuse'=>0),'id');
	$return['account']=$_SESSION['account'];	
	$params=array('worker_id'=>$this->worker_id,'uniacid'=>$_SESSION['uniacid']);
	$data['yuenum']=pdo_count('jy_yiliao_lesson_log',$params,'id');
	$thismonth = date('m');
	$thisyear = date('Y');
	$day = date("t",strtotime($year.'-'.$month));
	$tstart=strtotime($thisyear.'-'.$thismonth);
	$tend=strtotime($thisyear.'-'.$thismonth.'-'.$day);
	$params=array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$this->worker_id);
	$params['ontime between']=array($tstart,$tend);
	$params['status']=0;
	$data['yuenum']=pdo_count('jy_yiliao_lesson_pai',$params,'id');
	$data['allnum']=pdo_count('jy_yiliao_lesson_pai',array('status'=>array(0,1,2,3),'uniacid'=>$_SESSION['uniacid'],'workerid'=>$this->worker_id),'id');
	$return['data']=$data;
	set_html('title','医生中心');
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_yiliao_lesson_pai',array('id'=>$id,'workerid'=>$this->worker_id));
	$item['images']=$item['images']?json_decode($item['images'],true):array();
	$item['lesson']=pdo_get('jy_yiliao_lesson',array('id'=>$item['lessonid'],'uniacid'=>$_SESSION['uniacid']));
	$item['worker']=pdo_get('jy_yiliao_worker',array('id'=>$this->worker_id,'uniacid'=>$_SESSION['uniacid']));
	$item['store']=pdo_get('jy_yiliao_store',array('id'=>$item['storeid'],'uniacid'=>$_SESSION['uniacid']));
	$item['ontime']=$this->model('lesson')->get_uptime($item['ontime']);
	$item['statustitle']=$this->lesson_status[$item['status']];
	$item['storetitle']=pdo_getcolumn('jy_yiliao_store',array('id'=>$item['storeid'],'uniacid'=>$_SESSION['uniacid']),'title');
	$return['item']=$item;
	$return['post']=array('id'=>$item['id'],'onday'=>$item['onday'],'images'=>$item['images']);
	set_html('title','排班详情');
	exi($return);
}
if($_RQ['op']=='sign'){
	$postdata=get_postdata();
	$id=intval($postdata['id']);
	if($postdata['onday']!=date('Y-m-d')){
		exi('只有客户上门当天才能签到！','error');
	}
	$data=array(
		'lesson_paiid'=>$id,
		'type'=>1,
	);
	$this->model('model')->add_sign($data);
	pdo_update('jy_yiliao_lesson_pai',array('issign'=>1),array('id'=>$id,'workerid'=>$this->worker_id));
	exi('签到成功！');
}
if($_RQ['op']=='tingnum'){
	$postdata=get_postdata();
	$id=intval($postdata['id']);
	pdo_update('jy_yiliao_lesson_pai',array('tingnum'=>$postdata['tingnum']),array('id'=>$id,'workerid'=>$this->worker_id));
	exi('更新成功！');
}
if($_RQ['op']=='setimg'){
	$postdata=get_postdata();
	$id=intval($postdata['id']);
	pdo_update('jy_yiliao_lesson_pai',array('images'=>ijson_encode($postdata['images'])),array('id'=>$id,'workerid'=>$this->worker_id));
	exi('更新成功！');
}